1. Technology Field
The disclosure generally relates to a data writing method and a memory controller and a memory storage apparatus using the same, and more particularly, to a data writing method for writing data into a rewritable non-volatile memory module and a memory controller and a memory storage apparatus using the same.
2. Description of Related Art
Along with the widespread of digital cameras, cell phones, and MP3 in recently years, the consumers' demand to storage media has increased drastically. Rewritable non-volatile memory is one of the most adaptable storage media to portable electronic products (for example, notebook computers) due to its many characteristics such as data non-volatility, low power consumption, small volume, non-mechanical structure, and fast access speed. A solid state drive (SSD) is a storage apparatus which uses a flash memory as its storage medium. Thereby, the flash memory industry has become a very important part of the electronic industry in recent years.
Each sub memory module of a flash memory module has a plurality of physical blocks, and each of the physical blocks has a plurality of physical pages. While writing data into a physical block, the data has to be written according to the sequence of the physical pages in the physical block. In addition, a physical page already containing data has to be erased before it is used for writing new data. In particular, physical block is the smallest erasing unit, and physical page is the smallest programming (writing) unit. Thus, in the management of a flash memory module, the physical blocks thereof are categorized into a data area and a spare area.
Physical blocks (also referred to as data physical blocks) in the data area already contain data and are already mapped to logical blocks. To be specific, the memory management circuit of a memory storage apparatus converts a logical access address accessed by a host system into a logical page of a logical block, writes the data to be written into a physical page of a specific physical block, and maps the logical page of the logical block to the physical page of the physical block. Namely, in the management of a rewritable non-volatile memory module, the physical blocks in the data area are considered used physical blocks (for example, containing data written by a host system). The memory management circuit may record the mapping relationship between the logical blocks and the physical blocks of the data area in a logical block-physical block mapping table, wherein the logical pages of each of logical blocks are sequentially mapped to the physical pages of the corresponding physical block.
Physical blocks of the spare area are used for substituting the physical blocks of the data area. To be specific, as described above, a physical block already storing data has to be erased before it is used for writing new data. Thus, the physical blocks of the spare area are used for writing updated data to substitute the original physical blocks mapped to the logical blocks. Accordingly, the physical blocks of the spare area are either blank physical blocks or usable physical blocks (i.e., no data is recorded therein or data recorded therein is marked as invalid data).
Namely, in the management of a rewritable non-volatile memory module, the physical pages of the physical blocks in the data area and the spare area are alternatively mapped to the logical pages of the logical blocks for storing data written by a host system. Or, in some cases, the memory management circuit selects a plurality of physical blocks from the spare area for respectively storing data having different attributes but belonging to the same logical block. For example, the memory management circuit selects a physical block from the spare area as a global random physical block for storing updated data of small quantities and selects a physical block from the spare area as a log physical block (also referred to as a child physical block) of a specific data physical block for storing continuous updated data of large quantities. In particular, data in a logical page may be repeatedly updated and the updated data may be distributed into different physical blocks. Thus, both old and new data belonging to the same logical page may be stored in a rewritable non-volatile memory module. Conventionally, in order to identify such old and new data, the memory management circuit needs to update the logical page-physical page mapping table every time when a write command is executed.
During the operation of a memory storage apparatus, the mapping tables maintained by the memory management circuit are stored in a buffer memory so that they can be conveniently updated. Since the buffer memory is a volatile memory, in order to avoid data loss, the memory management circuit may store the mapping tables into the rewritable non-volatile memory module at predetermined intervals, or the memory management circuit may also store the mapping tables into the rewritable non-volatile memory module when the memory storage apparatus receives a shutdown command. However, a mapping table in the buffer memory which is not yet stored into the rewritable non-volatile memory module may be lost when a power failure occurs to the memory storage apparatus. Namely, when a power failure occurs, the memory management circuit cannot store the mapping tables in the buffer memory into the rewritable non-volatile memory module in time, and accordingly, when the memory storage apparatus is re-started, the memory management circuit cannot identify which data in the global random physical block and the child physical block is new or old data. Thereby, how to effectively identify the latest data after a power failure has become one of the major subjects in the industry.
Nothing herein should be construed as an admission of knowledge in the prior art of any portion of the present invention. Furthermore, citation or identification of any document in this application is not an admission that such document is available as prior art to the present invention, or that any reference forms a part of the common general knowledge in the art.